package advanced.practice._1004;

import java.io.PrintStream;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    static PrintStream out=System.out;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        int N=sc.nextInt();

        Stack<Node>stack=new Stack<>();
        Node root=null;
        Node current=null;
        for(int i=0;i<2*N;i++){
            String line=sc.nextLine().trim();
            if(line.isEmpty()){
                i--;
                continue;
            }

            if(line.length()<=3){//POP
                current=stack.pop();
            }else{
               int value=Integer.parseInt(line.substring(5));
               if(current==null){
                   root=new Node(value);
                   stack.push(root);
               }else{
                   Node node=new Node(value);
                   if(current.left==null){
                       current.left=node;
                   }else{
                       current.right=node;
                   }
                   stack.push(node);
               }

                current=stack.peek();
            }
        }

        out.println(root.postTraversal());
    }

}

class Node{
    int value;
    Node left;
    Node right;

    Node(int val){
        value=val;
    }

    String postTraversal(){
        StringBuilder builder=new StringBuilder();
        if(left!=null){
            builder.append(left.postTraversal());
            builder.append(" ");
        }
        if(right!=null){
            builder.append(right.postTraversal());
            builder.append(" ");
        }
        builder.append(value);

        return builder.toString().trim();
    }
}
